<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>注册账号</title>
<meta name="description" content="这是一个 index 页面">
<meta name="keywords" content="index">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="apple-mobile-web-app-title" content="Amaze UI" />
<link rel="stylesheet" href="/books/static/assets/css/amazeui.min.css" />
<link rel="stylesheet" href="/books/static/assets/css/amazeui.datatables.min.css" />
<link rel="stylesheet" href="/books/static/assets/css/app.css">
<script src="/books/static/jq/jquery-3.7.1.js"></script>
<script src="/books/static/assets/js/theme.js"></script>
</head>
<style>
	body {
			background-image: url("/books/static/images/02.jpg");
		}
</style>
<body data-type="login">
	<div class="am-g tpl-g">
		<!-- 风格切换 -->
		<div class="tpl-skiner">
			<div class="tpl-skiner-toggle am-icon-cog"></div>
			<div class="tpl-skiner-content">
				<div class="tpl-skiner-content-title">选择主题</div>
				<div class="tpl-skiner-content-bar">
					<span class="skiner-color skiner-white" data-color="theme-white"></span>
					<span class="skiner-color skiner-black" data-color="theme-black"></span>
				</div>
			</div>
		</div>
		<div class="tpl-login">
			<div class="tpl-login-content">
				<div class="tpl-login-title">注册用户</div>
				<span class="tpl-login-content-info">创建一个新的用户</span>

				<form class="am-form tpl-form-line-form" method="post"
					action="/books/userServlet/register" onsubmit="return check()" >
					<div class="am-form-group">
						<input type="text" class="tpl-form-input" id="user-name"
							name="userName" required="required" placeholder="请输入学号" >
							<span id="checkUserNameMessage"></span>
					</div>
					<div class="am-form-group">
						<input type="password" class="tpl-form-input" id="user-name"
							name="password" required="required" placeholder="请输入密码">
					</div>
					<div class="am-form-group">
						<input type="text" class="tpl-form-input" id="user-name"
							name="nickname" required="required" placeholder="请输入姓名">
					</div>
					<div class="am-form-group">
						<input type="text" class="tpl-form-input" id="user-name"
							name="email" required="required" placeholder="请输入邮箱">
					</div>
					<div class="am-form-group">
						<input type="text" class="tpl-form-input" id="user-name"
							name="phone" required="required" placeholder="请输入手机号">
					</div>
					<div class="am-form-group">
						<input type="text" class="tpl-form-input"  id="code" name="code"
									required="required" placeholder="验证码(点击图片更换)" />
						<span id = "checkCodeMessage"></span>
					</div>
					<div class="am-form-group">
						<img src="/books/codeServlet" id="checkCode"
									alt="验证码" />

					</div>
					
					<div class="am-form-group">
						<button type="submit"
							class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn" >注册</button>
					</div>
					<div class="am-form-group">
						<button type="button" onclick="location.href='/books/login.jsp';"
							class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn">返回登录</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
<script src="http://cdn.bootcss.com/amazeui/2.7.2/js/amazeui.min.js"></script>
<script src="/books/static/assets/js/app.js"></script>
<script>
	var result = false;
	
	//表单数据检验
	function check(){
		return result;
	}
	//验证输入的验证码
	$("#code").blur(function(){
		$.get("http://localhost:8080/books/userServlet/checkCode",{code:$("#code").val()},function(data){
			 if(data.code == 400){
				 $("#checkCodeMessage").text(data.message);
				 $("#checkCodeMessage").css("color","red");
				 result = false;
			 }else{
				 $("#checkCodeMessage").text(data.message);
				 $("#checkCodeMessage").css("color","green");
				 result = true;
			 }
		})
	});
	//验证输入的用户名
	$("#user-name").blur(function(){
		$.get("http://localhost:8080/books/userServlet/checkUser",{userName:$("#user-name").val()},function(data){
			 var obj = JSON.parse(data);
			 if(obj.code == 400){
				 $("#checkUserNameMessage").text(obj.message);
				 $("#checkUserNameMessage").css("color","red");
				 result = false;
			 }else{
				 $("#checkUserNameMessage").text(obj.message);
				 $("#checkUserNameMessage").css("color","green");
				 result = true;
			 }
		})
	});
	$("#checkCode").click(function(){
		//创建一个时间对象防止浏览器缓存
	    var d = new Date().getMilliseconds();
	    $("#checkCode").attr("src","/books/codeServlet?"+d);
	})
	
</script>
</html>